/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.business.controller;

import com.shop.cereshop.business.annotation.NoRepeatSubmit;
import com.shop.cereshop.business.annotation.NoRepeatWebLog;
import com.shop.cereshop.business.page.shop.Shop;
import com.shop.cereshop.business.param.live.CereShopAdressParam;
import com.shop.cereshop.business.param.shop.ShopParam;
import com.shop.cereshop.business.param.shop.ShopUpdateLogoParam;
import com.shop.cereshop.business.service.shop.*;
import com.shop.cereshop.business.utils.ContextUtil;
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.shop.*;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 店铺地址管理
 */
@RestController
@RequestMapping("shopAdress")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "CereShopReturnController")
@Api(value = "地址管理", tags = "地址管理")
public class CereShopReturnController {
    @Autowired
    private CereShopReturnService  cereShopReturnService;
    /**
     * 新增退货地址信息
     * @param cereShopReturn
     * @param request
     * @return
     */
    @PostMapping(value = "save")
    @NoRepeatSubmit
    @ApiOperation(value = "新增地址信息")
    @NoRepeatWebLog
    public Result save(@RequestBody CereShopReturn cereShopReturn, HttpServletRequest request) throws CoBusinessException{
        //获取当前登录账户

        cereShopReturn.setShopId(ContextUtil.getShopId());
        cereShopReturnService.insert(cereShopReturn);
        return Result.success();
    }

    /**
     * 删除退货地址信息
     * @param cereShopReturn
     * @param request
     * @return
     */
    @PostMapping(value = "delete")
    @NoRepeatSubmit
    @ApiOperation(value = "删除地址信息(已用)")
    @NoRepeatWebLog
    public Result delete(@RequestBody CereShopReturn cereShopReturn, HttpServletRequest request) throws CoBusinessException{
        //获取当前登录账户
        cereShopReturnService.deleteById(cereShopReturn.getId());
        return Result.success();
    }

    /**
     * 查询退货地址详情
     * @param cereShopReturn
     * @return
     */
    @PostMapping(value = "getDetail")
    @ApiOperation(value = "查询地址详情")
    public Result<CereShopReturn> getDetail(@RequestBody CereShopReturn cereShopReturn) throws CoBusinessException{
        CereShopReturn detail = cereShopReturnService.getById(cereShopReturn.getId());
        return Result.success(detail);
    }

    /**
     * 查询退货地址列表
     * @param param
     * @return
     */
    @PostMapping(value = "getAll")
    @ApiOperation(value = "查询地址列表")
    public Result<Page<CereShopReturn>> getList(@RequestBody CereShopAdressParam param) throws CoBusinessException{

        Page page  = cereShopReturnService.getAll(param);
        return Result.success(page);
    }
/**
 * 修改退货地址信息
 * @param cereShopReturn
 * @param request
 * @return
 */
@PostMapping(value = "update")
@NoRepeatSubmit
@ApiOperation(value = "修改地址信息(已用)")
@NoRepeatWebLog
public Result update(@RequestBody CereShopReturn cereShopReturn, HttpServletRequest request) throws CoBusinessException{
    //获取当前登录账户
    cereShopReturn.setShopId(ContextUtil.getShopId());
    cereShopReturnService.update(cereShopReturn);
    return Result.success();
}

}
